﻿// ------------------------------------------------------------------------------------------------
//  <copyright file="Page.cs" company="Iveely">
//    Copyright (c) Iveely Liu.  All rights reserved.
//  </copyright>
//  
//  <Create Time>
//    12/03/2012 20:12 
//  </Create Time>
//  
//  <contact owner>
//    liufanping@iveely.com 
//  </contact owner>
//  -----------------------------------------------------------------------------------------------

#region

using System;

#endregion

namespace IveelySE.Common.Html
{
    [Serializable]
    public class Page
    {
        /// <summary>
        ///   网页URL副本（因为有Rank判断所以必须有它）
        /// </summary>
        private string _url;

        /// <summary>
        ///   网页URL
        /// </summary>
        public string Url
        {
            get { return this._url; }

            set
            {
                this._url = value;
                this.UrlValue();
            }
        }

        /// <summary>
        ///   页面权值
        /// </summary>
        public double Rank { get; set; }

        /// <summary>
        ///   网页标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        ///   网页内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        ///   获取时间
        /// </summary>
        public string Date { get; set; }

        /// <summary>
        ///   网页类别
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        ///   是否已经分析过
        /// </summary>
        public bool Analysis { get; set; }

        /// <summary>
        ///   相近网页
        /// </summary>
        public string Relative { get; set; }

        ///// <summary>
        /////   The to string.
        ///// </summary>
        ///// <returns> The <see cref="string" /> . </returns>
        //public override string ToString()
        //{
        //    string title = "<br/><a  href='" + this.Url + "' target='_blank'>" + this.Title + "</a>" +
        //                   "<br/><font color='#0D960F'>" +
        //                   (this.Url.Length > 60 ? this.Url.Substring(0, 60) + "..." : this.Url) + "</font><br/>";
        //    string content = this.Content + "<br/>" + this.Relative + this.Date + "<br/>";

        //    // 返回数据
        //    return title + content;
        //}

        public override string ToString()
        {

            string formatInfor =
                string.Format(
                    "<h3 class='title'><a href='{2}'>{0}</a></h3><span class='url'>{2}</span></br><div class='desc'>{1}<div><span class='date'>{3}</span>",
                    this.Title,
                    this.Content,
                    this.Url.Length > 60 ? this.Url.Substring(0, 60) + "..." : this.Url,
                    this.Date);
            return "<li class='record'>" + formatInfor + "</li>";

        }

        /// <summary>
        ///   根据URL获取网页URL权值(反斜杠越少，说明是越上级目录)
        /// </summary>
        private void UrlValue()
        {
            var s = this._url;
            if (s != null)
            {
                this.Rank += s.Split('\\').Length / 0x989680;
            }
        }
    }
}